const express = require('express')
const Result = require('../../models/Result')
const { decoded } = require('../../utils/index')
const { PRIVATE_KEY, JWT_EXPIRED } = require('../../utils/constant')
const {
  getAreaList,
  editArea,
  createArea,
  deleteArea
} = require('../../services/teachingArea')
const jwt = require('jsonwebtoken')
const jwtAuth = require('../jwt')
// 注册路由
const router = express.Router()
router.use(jwtAuth)


//获取教学区列表接口
router.get('/list', function(req, res, next) {
  getAreaList(req.query).then(data => {
    new Result(data, '教学区信息查询成功').success(res)
  }).catch(err => {
    new Result('教学区信息查询失败').fail(res)
  })
})

//编辑教学区接口
router.post('/edit', function(req, res, next) {
  editArea(req.body).then(data => {
    new Result('操作成功').success(res)
  }).catch(err => {
    new Result('操作失败').fail(res)
  })
})

//创建教学区接口
router.post('/create', function(req, res, next) {
  createArea(req.body).then(data => {
    new Result('操作成功').success(res)
  }).catch(err => {
    new Result('操作失败').fail(res)
  })
})

//删除教学区接口
router.post('/delete', function(req, res, next) {
  deleteArea(req.body).then(data => {
    new Result('操作成功').success(res)
  }).catch(err => {
    new Result('操作失败').fail(res)
  })
})


module.exports = router